<template>
  <div class="home">
    <van-nav-bar
      title="所有适用门店"
      fixed
      left-arrow
      class="nav_bar"
      safe-area-inset-top
      @click-left="onClickLeft"
    />
    <div class="list">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <storeListItem
            v-for="(v, i) in list"
            :key="i"
            :item="v"
          ></storeListItem>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import storeListItem from "@/components/store/storeListItem";
import api from "@/api/api";
export default {
  components: { storeListItem },
  props: {},
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  watch: {},
  computed: {},
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;
      this.refreshing = true;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    onLoad() {
      if (this.refreshing) {
        this.list = [];
        this.refreshing = false;
      }
      this.getStoreList();
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;
      this.refreshing = true;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    async getStoreList() {
      api
        .getStoreList()
        .then((res) => {
          if (res.length == 0) this.finished = true;
          this.list = [...this.list, ...res];
          this.finished = true;
        })
        .finally(() => (this.loading = false));
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="less" scoped>
.home {
  min-height: 100vh;
  background: #fff0e3;
  padding: 160px 50px 150px 50px;
  /deep/ .van-icon {
    font-size: 50px;
    font-weight: bold;
    color: #333333;
  }
  .list {
    background: #fff;
    border-top-left-radius: 25px;
    border-top-right-radius: 25px;
    padding: 40px 50px 80px 50px;
  }
}
</style>